import request from '@/utils/request'
import qs from "qs";

// 获取所有的Role
export function getAll(params) {
  return request({
    url: 'admin/role/tree' + '?' + qs.stringify(params, {indices: false}),
    method: 'get'
  })
}

export function getRoleByUserId(id) {
  return request({
    url: `admin/role/user/${id}`,
    method: 'get'
  })
}

export function add(data) {
  return request({
    url: 'admin/role/save',
    method: 'post',
    data
  })
}

export function get(id) {
  return request({
    url: 'admin/role/' + id,
    method: 'get'
  })
}

export function del(ids) {
  return request({
    url: 'admin/role/del',
    method: 'post',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'admin/role/save',
    method: 'post',
    data
  })
}

export function editMenu(data) {
  return request({
    url: 'admin/role/menu',
    method: 'post',
    data
  })
}

export function getMenu(params) {
  return request({
    url: 'admin/role/menu',
    method: 'get',
    params
  })
}

export function allList(params) {
  return request({
    url: 'admin/role/all',
    method: 'post',
    params
  })
}

export function getRoleUserInfo(params) {
  return request({
    url: 'admin/role/getRoleUserInfo?roleId=' + params,
    method: 'get',
  })
}

export function getDeptUserTree(params) {
  return request({
    url: 'admin/role/getDeptUserTree',
    method: 'get',
    params
  })
}

export function getTreeInfoByRoleId(params) {
  return request({
    url: 'admin/role/getTreeInfoByRoleId?roleId=' + params,
    method: 'get',
    params
  })
}

export function bindUserRole(params) {
  return request({
    url: 'admin/role/bindUserRole?roleId=' + params.roleId + '&userIds=' + params.userIds,
    method: 'post'
  })
}

export function unbindUserRole(params) {
  return request({
    url: 'admin/role/unbindUserRole?roleId=' + params.roleId + '&userIds=' + params.userIds,
    method: 'post',
  })
}

export function getOne(params) {
  return request({
    url: 'admin/role/getOne?id=' + params,
    method: 'get',
  })
}

export default {
  getOne,
  unbindUserRole,
  bindUserRole,
  getTreeInfoByRoleId,
  getDeptUserTree,
  getRoleUserInfo,
  getAll,
  getMenu,
  add,
  edit,
  del,
  get,
  editMenu,
  allList
}
